package com.bobo.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.kafka.listener.MessageListener;

import com.alibaba.fastjson.JSON;
import com.bobo.domain.Trail;
import com.bobo.service.GoodsService;

public class MyListener implements MessageListener<String, String> {

	@Autowired
	GoodsService goodsService;

	@Override
	public void onMessage(ConsumerRecord<String, String> data) {
		String key = data.key();
		String value = data.value();
		System.out.println(key);
		if(key!=null) {
			if(key.equals("log")) {
				//1向操作轨迹表插入数据
				Trail trail = JSON.parseObject(value, Trail.class);
				goodsService.addTrail(trail);
			}
		}

	}

}
